.TH std::experimental::shuffle 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::experimental::shuffle \- std::experimental::shuffle

.SH Synopsis
   Defined in header <experimental/algorithm>
   template< class RandomIt >                      (library fundamentals TS v2)
   void shuffle( RandomIt first, RandomIt last );

   Reorders the elements in the given range [first, last) such that each possible
   permutation of those elements has equal probability of appearance, using the
   per-thread random number engine as the random number generator.

.SH Parameters

   first, last           -           the range of elements to shuffle randomly
   -
   RandomIt must meet the requirements of ValueSwappable and
   LegacyRandomAccessIterator.

.SH Return value

   \fI(none)\fP

.SH Complexity

   Linear in the distance between first and last.

.SH Example


// Run this code

 #include <experimental/algorithm>
 #include <iostream>
 #include <string>

 int main()
 {
     std::string sample{"ABCDEF"};

     for (int i = 0; i != 4; ++i)
     {
         std::experimental::shuffle(sample.begin(), sample.end());
         std::cout << sample << '\\n';
     }
 }

.SH Possible output:

 DACBFE
 CDFBAE
 BDCAFE
 BAFCED

.SH See also

   random_shuffle
   shuffle        randomly re-orders elements in a range
   \fI(until C++17)\fP  \fI(function template)\fP
   \fI(C++11)\fP
